package com.fanshuai2.niuke.strings;

import java.util.Scanner;
import java.util.Stack;

public class Calc {
    static boolean isDigit(char c) {
        return c >= '0' && c <= '9';
    }

    static boolean cmp(char c1, char c2) {
        if (c1 == '(') {
            return false;
        } else if ((c1 == '+' || c1 == '-') && (c2 == '*' || c2 == '/')) {
            return false;
        }
        return true;
    }
    static void doCal(Stack<Integer> datas, Stack<Character> ops) {
        int b = datas.pop();
        int a = datas.pop();
        int op = ops.pop();

        if (op == '+') {
            a = a+b;
        }
        if (op == '-') {
            a = a-b;
        }
        if (op == '*') {
            a = a*b;
        }
        if (op == '/') {
            a = a/b;
        }
        datas.push(a);
        return;
    }

    static int calc(String s) {
        if (null == s || s.length() == 0) {
            return 0;
        }

        Stack<Integer> datas = new Stack<>();
        Stack<Character> ops = new Stack<>();
        s = "(" + s + ")";

        char[] arr = s.toCharArray();
        int len = arr.length;

        boolean nextIsOp = false;
        for (int i = 0; i < len; i++) {
            char ch = arr[i];
            if (ch == ' ') {
                continue;
            }

            if (ch == '{' || ch == '[' || ch == '(') {
                ops.push('(');
            } else if (ch == '}' || ch == ']' || ch == ')') {
                while (!ops.isEmpty() && ops.peek() != '(') {
                    doCal(datas, ops);
                }
                ops.pop();
            } else if (nextIsOp) {
                while (!ops.isEmpty() && cmp(ops.peek(), ch)) {
                    doCal(datas, ops);
                }
                ops.push(ch);
                nextIsOp = false;
            } else {
                int k = i;
                if (ch == '+' || ch == '-') {
                    i++;
                }
                //数字
                while (isDigit(arr[i])) {
                    i++;
                }
                String t = s.substring(k, i);
                datas.push(Integer.valueOf(t));
                i--;

                nextIsOp = true;
            }
        }
        return datas.pop();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextLine()) {
            String s = in.nextLine();

            int v = calc(s);
            System.out.println(v);
        }
    }
}
